<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<html>
<head>
    <title>乐看系统分类管理</title>
    <meta name="decorator" content="default"/>
    <script type="text/javascript">
        $(document).ready(function () {
            //$("#name").focus();
            $("#inputForm").validate({
                submitHandler: function (form) {
                    loading('正在提交，请稍等...');
                    form.submit();
                },
                errorContainer: "#messageBox",
                errorPlacement: function (error, element) {
                    $("#messageBox").text("输入有误，请先更正。");
                    if (element.is(":checkbox") || element.is(":radio") || element.parent().is(".input-append")) {
                        error.appendTo(element.parent().parent());
                    } else {
                        error.insertAfter(element);
                    }
                }
            });
        });

        function addRow(list, idx, tpl, row) {
            $(list).append(Mustache.render(tpl, {
                idx: idx, delBtn: true, row: row
            }));
            $(list + idx).find("select").each(function () {
                $(this).val($(this).attr("data-value"));
            });
            $(list + idx).find("input[type='checkbox'], input[type='radio']").each(function () {
                var ss = $(this).attr("data-value").split(',');
                for (var i = 0; i < ss.length; i++) {
                    if ($(this).val() == ss[i]) {
                        $(this).attr("checked", "checked");
                    }
                }
            });
        }

        function delRow(obj, prefix) {
            var id = $(prefix + "_id");
            var delFlag = $(prefix + "_delFlag");
            if (id.val() == "") {
                $(obj).parent().parent().remove();
            } else if (delFlag.val() == "0") {
                delFlag.val("1");
                $(obj).html("&divide;").attr("title", "撤销删除");
                $(obj).parent().parent().addClass("error");
            } else if (delFlag.val() == "1") {
                delFlag.val("0");
                $(obj).html("&times;").attr("title", "删除");
                $(obj).parent().parent().removeClass("error");
            }
        }
    </script>
</head>
<body>
<ul class="nav nav-tabs">
    <li><a href="${ctx}/sys/adv/hkCategory/">乐看系统分类列表</a></li>
    <li class="active"><a href="${ctx}/sys/adv/hkCategory/form?id=${hkCategory.id}">乐看系统分类<shiro:hasPermission
            name="sys:adv:hkCategory:edit">${not empty hkCategory.id?'修改':'添加'}</shiro:hasPermission><shiro:lacksPermission
            name="sys:adv:hkCategory:edit">查看</shiro:lacksPermission></a></li>
</ul>
<br/>
<form:form id="inputForm" modelAttribute="hkCategory" action="${ctx}/sys/adv/hkCategory/save" method="post"
           class="form-horizontal">
    <form:hidden path="id"/>
    <sys:message content="${message}"/>
    <div class="control-group">
        <label class="control-label">上级父级编号:</label>
        <div class="controls">
            <sys:treeselect id="parent" name="parent.id" value="${hkCategory.parent.id}" labelName="parent.name"
                            labelValue="${hkCategory.parent.name}"
                            title="父级编号" url="/sys/adv/hkCategory/treeData" extId="${hkCategory.id}" cssClass=""
                            allowClear="true"/>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">所有父级编号：</label>
        <div class="controls">
            <form:input path="parentIds" htmlEscape="false" maxlength="2000" class="input-xlarge "/>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">名称：</label>
        <div class="controls">
            <form:input path="name" htmlEscape="false" maxlength="100" class="input-xlarge "/>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">标签颜色：</label>
        <div class="controls">
            <form:input path="labelColor" htmlEscape="false" maxlength="100" class="input-xlarge "/>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">排序：</label>
        <div class="controls">
            <form:input path="sort" htmlEscape="false" maxlength="11" class="input-xlarge "/>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">类型：</label>
        <div class="controls">
            <form:select path="type" class="input-xlarge ">
                <form:option value="" label=""/>
                <form:options items="${fns:getDictList('hk_source_model')}" itemLabel="label" itemValue="value"
                              htmlEscape="false"/>
            </form:select>
        </div>
    </div>

    <div class="control-group">
        <label class="control-label">编码：</label>
        <div class="controls">
            <form:input path="code" htmlEscape="false" maxlength="20" class="input-xlarge "/>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">级别：</label>
        <div class="controls">
            <form:input path="level" htmlEscape="false" maxlength="11" class="input-xlarge "/>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">图片地址：</label>
        <div class="controls">
            <form:hidden id="imgSrc" path="imgSrc" htmlEscape="false" maxlength="200" class="input-xlarge"/>
            <sys:ckfinder input="imgSrc" type="images" uploadPath="/hkCategory" selectMultiple="false"/>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">图片序号：</label>
        <div class="controls">
            <form:input path="imgRank" htmlEscape="false" maxlength="11" class="input-xlarge "/>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">备注：</label>
        <div class="controls">
            <form:textarea path="remarks" htmlEscape="false" rows="4" maxlength="100" class="input-xxlarge "/>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">乐看系统分类查询：</label>
        <div class="controls">
            <table id="contentTable" class="table table-striped table-bordered table-condensed">
                <thead>
                <tr>
                    <th class="hide"></th>

                    <th>分类查询</th>
                    <th>地区查询</th>


                    <th>备注</th>
                    <shiro:hasPermission name="sys:adv:hkCategory:edit">
                        <th width="10">&nbsp;</th>
                    </shiro:hasPermission>
                </tr>
                </thead>
                <tbody id="hkCategoryQueryList">
                </tbody>
                <shiro:hasPermission name="sys:adv:hkCategory:edit">
                    <tfoot>
                    <tr>
                        <td colspan="8"><a href="javascript:"
                                           onclick="addRow('#hkCategoryQueryList', hkCategoryQueryRowIdx, hkCategoryQueryTpl);hkCategoryQueryRowIdx = hkCategoryQueryRowIdx + 1;"
                                           class="btn">新增</a></td>
                    </tr>
                    </tfoot>
                </shiro:hasPermission>
            </table>
            <script type="text/template" id="hkCategoryQueryTpl">//<!--
						<tr id="hkCategoryQueryList{{idx}}">
							<td class="hide">
								<input id="hkCategoryQueryList{{idx}}_id" name="hkCategoryQueryList[{{idx}}].id" type="hidden" value="{{row.id}}"/>
								<input id="hkCategoryQueryList{{idx}}_delFlag" name="hkCategoryQueryList[{{idx}}].delFlag" type="hidden" value="0"/>
							</td>

							<td>
								<select id="hkCategoryQueryList{{idx}}_iscategoryquery" name="hkCategoryQueryList[{{idx}}].iscategoryquery" data-value="{{row.iscategoryquery}}" class="input-small ">
									<option value=""></option>
									<c:forEach items="${fns:getDictList('yes_no')}" var="dict">
										<option value="${dict.value}">${dict.label}</option>
									</c:forEach>
								</select>
							</td>
							<td>
								<select id="hkCategoryQueryList{{idx}}_regionalquery" name="hkCategoryQueryList[{{idx}}].regionalquery" data-value="{{row.regionalquery}}" class="input-small ">
									<option value=""></option>
									<c:forEach items="${fns:getDictList('yes_no')}" var="dict">
										<option value="${dict.value}">${dict.label}</option>
									</c:forEach>
								</select>
							</td>


							<td>
								<textarea id="hkCategoryQueryList{{idx}}_remarks" name="hkCategoryQueryList[{{idx}}].remarks" rows="4" maxlength="100" class="input-small ">{{row.remarks}}</textarea>
							</td>
							<shiro:hasPermission name="sys:adv:hkCategory:edit"><td class="text-center" width="10">
								{{#delBtn}}<span class="close" onclick="delRow(this, '#hkCategoryQueryList{{idx}}')" title="删除">&times;</span>{{/delBtn}}
							</td></shiro:hasPermission>
						</tr>//-->
            </script>
            <script type="text/javascript">
                var hkCategoryQueryRowIdx = 0,
                    hkCategoryQueryTpl = $("#hkCategoryQueryTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g, "");
                $(document).ready(function () {
                    var data = ${fns:toJson(hkCategory.hkCategoryQueryList)};
                    for (var i = 0; i < data.length; i++) {
                        addRow('#hkCategoryQueryList', hkCategoryQueryRowIdx, hkCategoryQueryTpl, data[i]);
                        hkCategoryQueryRowIdx = hkCategoryQueryRowIdx + 1;
                    }
                });
            </script>
        </div>
    </div>
    <div class="form-actions">
        <shiro:hasPermission name="sys:adv:hkCategory:edit"><input id="btnSubmit" class="btn btn-primary" type="submit"
                                                                   value="保 存"/>&nbsp;</shiro:hasPermission>
        <input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
    </div>
</form:form>
</body>
</html>